
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>12.整数转罗马数字 · Gary的小窝</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Gary">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-solarizedlight.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="13.html" />
    
    
    <link rel="prev" href="11.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    写在前面
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="./">
            
                <a href="./">
            
                    
                    Leetcode之旅
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="1.html">
            
                <a href="1.html">
            
                    
                    1.两数之和
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="2.html">
            
                <a href="2.html">
            
                    
                    2.两数相加
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="3.html">
            
                <a href="3.html">
            
                    
                    3.无重复字符的最长子串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="4.html">
            
                <a href="4.html">
            
                    
                    4.寻找两个有序数组的中位数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="6.html">
            
                <a href="6.html">
            
                    
                    6.Z字形变换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="9.html">
            
                <a href="9.html">
            
                    
                    9.回文数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="11.html">
            
                <a href="11.html">
            
                    
                    11.盛最多水的容器
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.8" data-path="12.html">
            
                <a href="12.html">
            
                    
                    12.整数转罗马数字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="13.html">
            
                <a href="13.html">
            
                    
                    13.罗马数字转整数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="14.html">
            
                <a href="14.html">
            
                    
                    14.最长公共前缀
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="322.html">
            
                <a href="322.html">
            
                    
                    322.零钱兑换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="72.html">
            
                <a href="72.html">
            
                    
                    72.编辑距离
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../flutter/">
            
                <a href="../flutter/">
            
                    
                    Flutter从入门到放弃
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../flutter/dart1.html">
            
                <a href="../flutter/dart1.html">
            
                    
                    1.Dart语言(1)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../flutter/dart2.html">
            
                <a href="../flutter/dart2.html">
            
                    
                    2.Dart语言(2)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../flutter/widget1.html">
            
                <a href="../flutter/widget1.html">
            
                    
                    3.Flutter初始化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../flutter/containerText.html">
            
                <a href="../flutter/containerText.html">
            
                    
                    4.Container和Text组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../flutter/image.html">
            
                <a href="../flutter/image.html">
            
                    
                    5.Image组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../flutter/chapter2.html">
            
                <a href="../flutter/chapter2.html">
            
                    
                    6.Flutter 技术总结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../vue/">
            
                <a href="../vue/">
            
                    
                    Vue组件精讲
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../vue/1.html">
            
                <a href="../vue/1.html">
            
                    
                    1.provide/inject
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../vue/2.html">
            
                <a href="../vue/2.html">
            
                    
                    2.手动实现broadcast和dispatch方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../js/form.html">
            
                <a href="../js/form.html">
            
                    
                    3.自己动手实现带校验的Form表单组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../js/">
            
                <a href="../js/">
            
                    
                    JavaScript进阶
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../js/proxy.html">
            
                <a href="../js/proxy.html">
            
                    
                    1.Vue.js 3.0中的响应式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../js/el.html">
            
                <a href="../js/el.html">
            
                    
                    2.Element UI 源码初探
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../js/bind.html">
            
                <a href="../js/bind.html">
            
                    
                    3.bind的模拟实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../js/proto.html">
            
                <a href="../js/proto.html">
            
                    
                    4.JS原型和原型链
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../js/call.html">
            
                <a href="../js/call.html">
            
                    
                    5.模拟实现call和apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../js/ui.html">
            
                <a href="../js/ui.html">
            
                    
                    6.使用Vue cli3搭建组件库并发布到 npm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../js/microFE.html">
            
                <a href="../js/microFE.html">
            
                    
                    7.记一次基于qiankun的微前端的改造
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../js/git.html">
            
                <a href="../js/git.html">
            
                    
                    8.Git的使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../vueLibrary/">
            
                <a href="../vueLibrary/">
            
                    
                    基于Vue的PC端的组件库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../vueLibrary/1.html">
            
                <a href="../vueLibrary/1.html">
            
                    
                    1.环境搭建
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../life/">
            
                <a href="../life/">
            
                    
                    网事杂谈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../life/1.html">
            
                <a href="../life/1.html">
            
                    
                    1.周杰伦专辑赏析--叶惠美
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../life/2.html">
            
                <a href="../life/2.html">
            
                    
                    2.周杰伦专辑赏析--七里香
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >12.整数转罗马数字</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#012-&#x6574;&#x6570;&#x8F6C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;"><b></b>012. &#x6574;&#x6570;&#x8F6C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;</a></li><li><span class="title-icon "></span><a href="#&#x4E00;-&#x9898;&#x76EE;&#x63CF;&#x8FF0;"><b></b>&#x4E00; &#x9898;&#x76EE;&#x63CF;&#x8FF0;</a></li><li><span class="title-icon "></span><a href="#&#x4E8C;-&#x89E3;&#x9898;&#x8FC7;&#x7A0B;"><b></b>&#x4E8C; &#x89E3;&#x9898;&#x8FC7;&#x7A0B;</a></li><li><span class="title-icon "></span><a href="#&#x4E09;-&#x601D;&#x8003;"><b></b>&#x4E09; &#x601D;&#x8003;</a></li><li><span class="title-icon "></span><a href="#&#x56DB;-&#x8D2A;&#x5FC3;&#x7B97;&#x6CD5;"><b></b>&#x56DB; &#x8D2A;&#x5FC3;&#x7B97;&#x6CD5;</a></li></ul></div><a href="#012-&#x6574;&#x6570;&#x8F6C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-19 10:53:16
 * @LastEditTime: 2019-08-19 15:18:26
 * @LastEditors: Please set LastEditors
 -->
<h1 id="012-&#x6574;&#x6570;&#x8F6C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;"><a name="012-&#x6574;&#x6570;&#x8F6C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;" class="anchor-navigation-ex-anchor" href="#012-&#x6574;&#x6570;&#x8F6C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;"><i class="fa fa-link" aria-hidden="true"></i></a>012. &#x6574;&#x6570;&#x8F6C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;</h1>
<h1 id="&#x4E00;-&#x9898;&#x76EE;&#x63CF;&#x8FF0;"><a name="&#x4E00;-&#x9898;&#x76EE;&#x63CF;&#x8FF0;" class="anchor-navigation-ex-anchor" href="#&#x4E00;-&#x9898;&#x76EE;&#x63CF;&#x8FF0;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E00; &#x9898;&#x76EE;&#x63CF;&#x8FF0;</h1>
<blockquote>
<p>&#x7F57;&#x9A6C;&#x6570;&#x5B57;&#x5305;&#x542B;&#x4EE5;&#x4E0B;&#x4E03;&#x79CD;&#x5B57;&#x7B26;&#xFF1A; I&#xFF0C; V&#xFF0C; X&#xFF0C; L&#xFF0C;C&#xFF0C;D &#x548C; M&#x3002;</p>
</blockquote>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5B57;&#x7B26;</th>
<th style="text-align:left">&#x6570;&#x503C;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">I</td>
<td style="text-align:left">1</td>
</tr>
<tr>
<td style="text-align:left">V</td>
<td style="text-align:left">5</td>
</tr>
<tr>
<td style="text-align:left">X</td>
<td style="text-align:left">10</td>
</tr>
<tr>
<td style="text-align:left">L</td>
<td style="text-align:left">50</td>
</tr>
<tr>
<td style="text-align:left">C</td>
<td style="text-align:left">100</td>
</tr>
<tr>
<td style="text-align:left">D</td>
<td style="text-align:left">500</td>
</tr>
<tr>
<td style="text-align:left">M</td>
<td style="text-align:left">1000</td>
</tr>
</tbody>
</table>
<blockquote>
<p>&#x4F8B;&#x5982;&#xFF0C; &#x7F57;&#x9A6C;&#x6570;&#x5B57; 2 &#x5199;&#x505A; II &#xFF0C;&#x5373;&#x4E3A;&#x4E24;&#x4E2A;&#x5E76;&#x5217;&#x7684; 1&#x3002;12 &#x5199;&#x505A; XII &#xFF0C;&#x5373;&#x4E3A; X + II &#x3002; 27 &#x5199;&#x505A;  XXVII, &#x5373;&#x4E3A; XX + V + II &#x3002;</p>
</blockquote>
<p>&#x901A;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;&#x4E2D;&#x5C0F;&#x7684;&#x6570;&#x5B57;&#x5728;&#x5927;&#x7684;&#x6570;&#x5B57;&#x7684;&#x53F3;&#x8FB9;&#x3002;&#x4F46;&#x4E5F;&#x5B58;&#x5728;&#x7279;&#x4F8B;&#xFF0C;&#x4F8B;&#x5982; 4 &#x4E0D;&#x5199;&#x505A; IIII&#xFF0C;&#x800C;&#x662F; IV&#x3002;&#x6570;&#x5B57; 1 &#x5728;&#x6570;&#x5B57; 5 &#x7684;&#x5DE6;&#x8FB9;&#xFF0C;&#x6240;&#x8868;&#x793A;&#x7684;&#x6570;&#x7B49;&#x4E8E;&#x5927;&#x6570; 5 &#x51CF;&#x5C0F;&#x6570; 1 &#x5F97;&#x5230;&#x7684;&#x6570;&#x503C; 4 &#x3002;&#x540C;&#x6837;&#x5730;&#xFF0C;&#x6570;&#x5B57; 9 &#x8868;&#x793A;&#x4E3A; IX&#x3002;&#x8FD9;&#x4E2A;&#x7279;&#x6B8A;&#x7684;&#x89C4;&#x5219;&#x53EA;&#x9002;&#x7528;&#x4E8E;&#x4EE5;&#x4E0B;&#x516D;&#x79CD;&#x60C5;&#x51B5;&#xFF1A;</p>
<blockquote>
<p>I &#x53EF;&#x4EE5;&#x653E;&#x5728; V (5) &#x548C; X (10) &#x7684;&#x5DE6;&#x8FB9;&#xFF0C;&#x6765;&#x8868;&#x793A; 4 &#x548C; 9&#x3002;
X &#x53EF;&#x4EE5;&#x653E;&#x5728; L (50) &#x548C; C (100) &#x7684;&#x5DE6;&#x8FB9;&#xFF0C;&#x6765;&#x8868;&#x793A; 40 &#x548C; 90&#x3002; 
C &#x53EF;&#x4EE5;&#x653E;&#x5728; D (500) &#x548C; M (1000) &#x7684;&#x5DE6;&#x8FB9;&#xFF0C;&#x6765;&#x8868;&#x793A; 400 &#x548C; 900&#x3002;</p>
</blockquote>
<p>&#x7ED9;&#x5B9A;&#x4E00;&#x4E2A;&#x6574;&#x6570;&#xFF0C;&#x5C06;&#x5176;&#x8F6C;&#x4E3A;&#x7F57;&#x9A6C;&#x6570;&#x5B57;&#x3002;&#x8F93;&#x5165;&#x786E;&#x4FDD;&#x5728; 1 &#x5230; 3999 &#x7684;&#x8303;&#x56F4;&#x5185;&#x3002;</p>
<p>&#x793A;&#x4F8B;1&#xFF1A;</p>
<pre class="language-"><code>&#x8F93;&#x5165;: 3
&#x8F93;&#x51FA;: &quot;III&quot;
</code></pre><p>&#x793A;&#x4F8B;2&#xFF1A;</p>
<pre class="language-"><code>&#x8F93;&#x5165;: 4
&#x8F93;&#x51FA;: &quot;IV&quot;
</code></pre><p>&#x793A;&#x4F8B;3&#xFF1A;</p>
<pre class="language-"><code>&#x8F93;&#x5165;: 9
&#x8F93;&#x51FA;: &quot;IX&quot;
</code></pre><p>&#x793A;&#x4F8B;4&#xFF1A;</p>
<pre class="language-"><code>&#x8F93;&#x5165;: 58
&#x8F93;&#x51FA;: &quot;LVIII&quot;
&#x89E3;&#x91CA;: L = 50, V = 5, III = 3.
</code></pre><p>&#x793A;&#x4F8B;5&#xFF1A;</p>
<pre class="language-"><code>&#x8F93;&#x5165;: 1994
&#x8F93;&#x51FA;: &quot;MCMXCIV&quot;
&#x89E3;&#x91CA;: M = 1000, CM = 900, XC = 90, IV = 4.
</code></pre><h1 id="&#x4E8C;-&#x89E3;&#x9898;&#x8FC7;&#x7A0B;"><a name="&#x4E8C;-&#x89E3;&#x9898;&#x8FC7;&#x7A0B;" class="anchor-navigation-ex-anchor" href="#&#x4E8C;-&#x89E3;&#x9898;&#x8FC7;&#x7A0B;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E8C; &#x89E3;&#x9898;&#x8FC7;&#x7A0B;</h1>
<p>&#x601D;&#x8DEF;&#x8FD8;&#x662F;&#x6BD4;&#x8F83;&#x6E05;&#x6670;&#x7684;  &#x628A;&#x6BCF;&#x4F4D;&#x6570;&#x5B57; &#x53D6;&#x51FA;&#x6765; &#x6839;&#x636E;&#x4E0D;&#x540C;&#x60C5;&#x51B5;&#x5224;&#x65AD; &#x662F;&#x5426;&#x662F;4 &#x6216;&#x8005;&#x662F;5&#x6216;&#x8005;9 &#x8F6C;&#x6362;&#x6210;&#x7F57;&#x9A6C;&#x6570;&#x5B57; &#x6700;&#x540E;&#x62FC;&#x6210;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;</p>
<pre class="language-"><code class="lang-JavaScript">/**
 * @param {number} num
 * @return {string}
 */
var intToRoman = function(num) {
    // &#x8F93;&#x5165;&#x7684;&#x6570;&#x5B57;&#x5728;1&#x5230;3999 &#x8303;&#x56F4;&#x5185;
    if(num &gt; 3999 || num &lt; 1){
        return 0;
    }
    var obj  = {onet:&apos;M&apos;,fhun:&apos;D&apos;,ohun:&apos;C&apos;,fifty:&apos;L&apos;,ten:&apos;X&apos;,five:&apos;V&apos;,one:&apos;I&apos;};
    var res = &apos;&apos;;
    var thousand = Math.floor(num/1000);
    // &#x5343;&#x4F4D; &#x53EA;&#x53EF;&#x80FD;&#x662F; 0 1 2 3
    if(thousand &gt; 0){
        for(var i = 0 ; i &lt; thousand ; i ++ ){
            res = res + obj.onet
        }
    }

    var hundred =Math.floor((num- thousand*1000)/100);
    if(hundred&gt;0 &amp;&amp; hundred&lt;4){
        for(var i = 0 ; i &lt; hundred ; i ++ ){
            res = res + obj.ohun
        }
    }
    if(hundred == 4){
           res = res + obj.ohun+ obj.fhun
    }
    if(hundred &gt; 4 &amp;&amp; hundred&lt;9){
         res = res + obj.fhun
        for(var i = 0 ; i &lt; hundred-5 ; i ++ ){
            res = res + obj.ohun
        }
    }

    if(hundred == 9){
           res = res + obj.ohun+ obj.onet
    }
    //&#x5341;&#x4F4D; 
    var ten = Math.floor((num- thousand*1000-hundred*100)/10)
    if(ten&gt;0 &amp;&amp; ten&lt;4){
        for(var i = 0 ; i &lt; ten ; i ++ ){
            res = res + obj.ten
        }
    }
    if(ten == 4){
           res = res + obj.ten+ obj.fifty
    }
    if(ten &gt; 4 &amp;&amp; ten&lt;9){
        res = res + obj.fifty
        for(var i = 0 ; i &lt; ten-5 ; i ++ ){
            res = res + obj.ten
        }
    }

    if(ten == 9){
           res = res + obj.ten+ obj.ohun
    }

    var one = (num- thousand*1000-hundred*100)%10

    if(one&gt;0 &amp;&amp; one&lt;4){
        for(var i = 0 ; i &lt; one ; i ++ ){
            res = res + obj.one
        }
    }
    if(one == 4){
           res = res + obj.one+ obj.five
    }
    if(one &gt; 4 &amp;&amp; one&lt;9){
        res = res + obj.five
        for(var i = 0 ; i &lt; one-5 ; i ++ ){
            res = res + obj.one
        }
    }
    if(one == 9){
           res = res + obj.one+ obj.ten
    }
    return res;   
};
</code></pre>
<h1 id="&#x4E09;-&#x601D;&#x8003;"><a name="&#x4E09;-&#x601D;&#x8003;" class="anchor-navigation-ex-anchor" href="#&#x4E09;-&#x601D;&#x8003;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E09; &#x601D;&#x8003;</h1>
<p>&#x4E0A;&#x8FF0;&#x89E3;&#x6CD5;&#x662F;&#x6BD4;&#x8F83;&#x66B4;&#x529B;&#x7684; &#x5F53;&#x6211;&#x67E5;&#x770B;&#x4E86;&#x5B98;&#x65B9;&#x9898;&#x89E3;&#x540E;&#xFF0C;&#x53D1;&#x73B0;&#x4E86;&#x4E00;&#x79CD;&#x65B0;&#x7684;&#x89E3;&#x6CD5;&#xFF0C;&#x8D2A;&#x5FC3;&#x7B97;&#x6CD5;&#x3002;</p>
<h1 id="&#x56DB;-&#x8D2A;&#x5FC3;&#x7B97;&#x6CD5;"><a name="&#x56DB;-&#x8D2A;&#x5FC3;&#x7B97;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x56DB;-&#x8D2A;&#x5FC3;&#x7B97;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x56DB; &#x8D2A;&#x5FC3;&#x7B97;&#x6CD5;</h1>
<p>&#x5728;&#x751F;&#x6D3B;&#x4E2D;&#x7684;&#x4F8B;&#x5B50;&#xFF1A;</p>
<blockquote>
<p>&#x5728;&#x4EE5;&#x524D;&#x8FD8;&#x4F7F;&#x7528;&#x73B0;&#x91D1;&#x8D2D;&#x7269;&#x7684;&#x5E74;&#x4EE3;&#xFF0C;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x4E0D;&#x60F3;&#x8BA9;&#x5BF9;&#x65B9;&#x627E;&#x94B1;&#xFF0C;&#x4ED8;&#x6B3E;&#x7684;&#x65F6;&#x5019;&#x6211;&#x4EEC;&#x4F1A;&#x5C3D;&#x91CF;&#x62FF;&#x9762;&#x503C;&#x5927;&#x7684;&#x7EB8;&#x5E01;&#x7ED9;&#x5BF9;&#x65B9;&#xFF0C;&#x8FD9;&#x6837;&#x624D;&#x4F1A;&#x4F7F;&#x5F97;&#x6211;&#x4EEC;&#x7ED9;&#x5BF9;&#x65B9;&#x7684;&#x7EB8;&#x5E01;&#x5F20;&#x6570;&#x6700;&#x5C11;&#xFF0C;&#x5BF9;&#x65B9;&#x70B9;&#x94B1;&#x7684;&#x65F6;&#x5019;&#xFF08;&#x56E0;&#x4E3A;&#x5BF9;&#x65B9;&#x8981;&#x68C0;&#x9A8C;&#x4F60;&#x7ED9;&#x7684;&#x94B1;&#x5BF9;&#x4E0D;&#x5BF9;&#xFF09;&#x4E5F;&#x6700;&#x65B9;&#x4FBF;&#x3002;&#x6700;&#x6781;&#x7AEF;&#x7684;&#x4E00;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x4F60;&#x8981;&#x662F;&#x90FD;&#x62FF;&#x96F6;&#x94B1;&#x53BB;&#x4E70;&#x4E00;&#x4E2A;&#x6BD4;&#x8F83;&#x8D35;&#x91CD;&#x7684;&#x4E1C;&#x897F;&#xFF0C;&#x6211;&#x76F8;&#x4FE1;&#x6CA1;&#x6709;&#x4EBA;&#x662F;&#x5F88;&#x9AD8;&#x5174;&#x6536;&#x5230;&#x4F60;&#x7684;&#x94B1;&#x7684;&#xFF0C;&#x56E0;&#x4E3A;&#x4ED6;&#x4EEC;&#x70B9;&#x94B1;&#x8D39;&#x52B2;&#x3002;</p>
</blockquote>
<p>&#x6574;&#x6570;&#x8F6C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;&#x201D;&#x4E0E;&#x4E0A;&#x9762;&#x7684;&#x95EE;&#x9898;&#x662F;&#x4E00;&#x6A21;&#x4E00;&#x6837;&#x7684;&#x601D;&#x60F3;&#xFF1A;&#x5728;&#x8868;&#x793A;&#x4E00;&#x4E2A;&#x8F83;&#x5927;&#x6574;&#x6570;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x201C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;&#x201D;&#x4E0D;&#x4F1A;&#x8BA9;&#x4F60;&#x90FD;&#x7528; 11 &#x52A0;&#x8D77;&#x6765;&#xFF0C;&#x80AF;&#x5B9A;&#x662F;&#x5199;&#x51FA;&#x6765;&#x7684;&#x201C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;&#x201D;&#x7684;&#x4E2A;&#x6570;&#x8D8A;&#x5C11;&#x8D8A;&#x597D;&#x3002;</p>
<p>&#x4E8E;&#x8FD9;&#x9053;&#x95EE;&#x9898;&#xFF0C;&#x201C;&#x7EB8;&#x5E01;&#x201D;&#x6709;&#x54EA;&#x4E9B;&#xFF0C;&#x5E76;&#x4E0D;&#x662F;&#x53EA;&#x6709;&#x9898;&#x76EE;&#x4E2D;&#x7ED9;&#x51FA;&#x7684;&#x5BF9;&#x5E94;&#x5173;&#x7CFB;&#xFF0C;&#x6839;&#x636E;&#x89C4;&#x5219;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x5F97;&#x5230;&#x4E00;&#x4E9B;&#x201C;&#x7EB8;&#x5E01;&#x201D;&#x7684;&#x9762;&#x503C;&#xFF0C;&#x4E0D;&#x8FC7;&#x90FD;&#x662F;&#x6709;&#x9650;&#x4E2A;&#x201C;&#x7EB8;&#x5E01;&#x201D;&#xFF0C;&#x5F88;&#x5FEB;&#x5C31;&#x80FD;&#x7F57;&#x5217;&#x51FA;&#x6765;&#x3002;</p>
<p>&#x4E8E;&#x662F;&#x89E3;&#x8FD9;&#x9053;&#x9898;&#x7684;&#x601D;&#x8DEF;&#x5C31;&#x51FA;&#x6765;&#x4E86;&#xFF1A;</p>
<blockquote>
<p>&#x201C;&#x7EB8;&#x5E01;&#x201D;&#x6709;&#x54EA;&#x4E9B;&#xFF1F;
&#x4E00;&#x4E2A;&#x6574;&#x6570;&#x5982;&#x4F55;&#x505A;&#x201C;&#x52A0;&#x6CD5;&#x56E0;&#x5B50;&#x201D;&#x7684;&#x5206;&#x89E3;&#xFF1F;</p>
</blockquote>
<p>&#x601D;&#x8DEF;&#x5206;&#x6790;&#xFF1A;</p>
<p>&#x4ECE;&#x9898;&#x76EE;&#x4E2D;&#x7ED9;&#x51FA;&#x7684;&#x201C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;&#x201D;&#x4E0E;&#x963F;&#x62C9;&#x4F2F;&#x6570;&#x5B57;&#x7684;&#x5BF9;&#x5E94;&#x5173;&#x7CFB;&#xFF0C;&#x548C;&#x7FFB;&#x8BD1;&#x89C4;&#x5219;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x63A8;&#x5BFC;&#x51FA;&#x201C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;&#x201D;&#x8FD8;&#x6709;&#x54EA;&#x4E9B;&#x7EC4;&#x5408;&#x3002;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x7F57;&#x9A6C;&#x6570;&#x5B57;</th>
<th style="text-align:left">&#x963F;&#x62C9;&#x4F2F;&#x6570;&#x5B57;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">I</td>
<td style="text-align:left">1</td>
</tr>
<tr>
<td style="text-align:left">V</td>
<td style="text-align:left">5</td>
</tr>
<tr>
<td style="text-align:left">X</td>
<td style="text-align:left">10</td>
</tr>
<tr>
<td style="text-align:left">L</td>
<td style="text-align:left">50</td>
</tr>
<tr>
<td style="text-align:left">C</td>
<td style="text-align:left">100</td>
</tr>
<tr>
<td style="text-align:left">D</td>
<td style="text-align:left">500</td>
</tr>
<tr>
<td style="text-align:left">M</td>
<td style="text-align:left">1000</td>
</tr>
</tbody>
</table>
<p>&#x4E3A;&#x6B64;&#xFF0C;&#x6211;&#x4EEC;&#x8981;&#x4E3E;&#x4F8B;&#x5B50;&#x5E2E;&#x52A9;&#x6211;&#x4EEC;&#x53D1;&#x73B0;&#x89C4;&#x5F8B;&#xFF1A;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x963F;&#x62C9;&#x4F2F;&#x6570;&#x5B57;</th>
<th style="text-align:left">&#x8F6C;&#x6362;&#x89C4;&#x5219;</th>
<th style="text-align:left">&#x7F57;&#x9A6C;&#x6570;&#x5B57;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">1</td>
<td style="text-align:left">&#x76F4;&#x63A5;&#x770B;&#x8868;</td>
<td style="text-align:left">I</td>
</tr>
<tr>
<td style="text-align:left">2</td>
<td style="text-align:left">2=1+1&#xFF0C;&#x76F8;&#x540C;&#x6570;&#x5B57;&#x7B80;&#x5355;&#x53E0;&#x52A0;</td>
<td style="text-align:left">II</td>
</tr>
<tr>
<td style="text-align:left">3</td>
<td style="text-align:left">3=1+1+1&#xFF0C;&#x76F8;&#x540C;&#x6570;&#x5B57;&#x7B80;&#x5355;&#x53E0;&#x52A0;</td>
<td style="text-align:left">III</td>
</tr>
<tr>
<td style="text-align:left">4</td>
<td style="text-align:left">&#x4E0D;&#x80FD;&#x5199;&#x6210; 4 = 1 + 1 + 1 + 14=1+1+1+1&#xFF0C;44 &#x5E94;&#x8BE5;&#x770B;&#x505A; 4 = 5 - 14=5&#x2212;1</td>
<td style="text-align:left">IV</td>
</tr>
<tr>
<td style="text-align:left">5</td>
<td style="text-align:left">&#x76F4;&#x63A5;&#x770B;&#x8868;</td>
<td style="text-align:left">V</td>
</tr>
<tr>
<td style="text-align:left">6</td>
<td style="text-align:left">6=5+1&#xFF0C;&#x5927;&#x6570;&#x5B57;&#x5728;&#x524D;&#xFF0C;&#x5C0F;&#x6570;&#x5B57;&#x5728;&#x540E;</td>
<td style="text-align:left">VI</td>
</tr>
<tr>
<td style="text-align:left">7</td>
<td style="text-align:left">7=5+1+1&#xFF0C;&#x5927;&#x6570;&#x5B57;&#x5728;&#x524D;&#xFF0C;&#x5C0F;&#x6570;&#x5B57;&#x5728;&#x540E;&#xFF0C;&#x76F8;&#x540C;&#x6570;&#x5B57;&#x7B80;&#x5355;&#x53E0;&#x52A0;</td>
<td style="text-align:left">VII</td>
</tr>
<tr>
<td style="text-align:left">8</td>
<td style="text-align:left">8=5+1+1+1&#xFF0C;&#x5927;&#x6570;&#x5B57;&#x5728;&#x524D;&#xFF0C;&#x5C0F;&#x6570;&#x5B57;&#x5728;&#x540E;&#xFF0C;&#x76F8;&#x540C;&#x6570;&#x5B57;&#x7B80;&#x5355;&#x53E0;&#x52A0;</td>
<td style="text-align:left">VIII</td>
</tr>
<tr>
<td style="text-align:left">9</td>
<td style="text-align:left">&#x4E0D;&#x80FD;&#x5199;&#x6210; 9 = 5 + 1 + 1 + 1 + 19=5+1+1+1+1&#xFF0C;99 &#x5E94;&#x8BE5;&#x770B;&#x505A; 9 = 10 - 19=10&#x2212;1</td>
<td style="text-align:left">IX</td>
</tr>
<tr>
<td style="text-align:left">10</td>
<td style="text-align:left">&#x76F4;&#x63A5;&#x770B;&#x8868;</td>
<td style="text-align:left">X</td>
</tr>
</tbody>
</table>
<p> &#x4E8E;&#x662F;&#xFF0C;&#x6211;&#x4EEC;&#x53D1;&#x73B0;&#xFF08;&#x5176;&#x5B9E;&#x5728;&#x9898;&#x76EE;&#x4E2D;&#x5DF2;&#x7ECF;&#x5F3A;&#x8C03;&#x4E86;&#x8FD9;&#x4E9B;&#x7279;&#x4F8B;&#xFF09;&#xFF0C;&#x51FA;&#x73B0; 44&#x3001;99&#x3001;4040&#x3001;9090&#x3001;400400&#x3001;900900 &#xFF08;40004000&#x3001;90009000 &#x4E0D;&#x8BA8;&#x8BBA;&#x4E86;&#xFF0C;&#x9898;&#x76EE;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#x4E2D;&#x6709;&#x8BF4;&#xFF0C;&#x4E0D;&#x4F1A;&#x8D85;&#x8FC7; 39993999&#xFF09;&#x7684;&#x60C5;&#x51B5;&#x6BD4;&#x8F83;&#x7279;&#x6B8A;&#x4E00;&#x4E9B;&#xFF0C;&#x505A;&#x7684;&#x662F;&#x51CF;&#x6CD5;&#xFF0C;&#x628A;&#x5B83;&#x4EEC;&#x4E5F;&#x52A0;&#x5165;&#x5230;&#x201C;&#x7F57;&#x9A6C;&#x6570;&#x5B57;&#x201D;&#x4E0E;&#x963F;&#x62C9;&#x4F2F;&#x6570;&#x5B57;&#x7684;&#x5BF9;&#x5E94;&#x5173;&#x7CFB;&#x8868;&#x4E2D;&#xFF0C;&#x5E76;&#x4E14;&#x6309;&#x7167;&#x4ECE;&#x5927;&#x5230;&#x5C0F;&#x7684;&#x987A;&#x5E8F;&#x6392;&#x5217;&#x3002;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x7F57;&#x9A6C;&#x6570;&#x5B57;</th>
<th style="text-align:left">&#x963F;&#x62C9;&#x4F2F;&#x6570;&#x5B57;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">M</td>
<td style="text-align:left">1000</td>
</tr>
<tr>
<td style="text-align:left">CM</td>
<td style="text-align:left">900</td>
</tr>
<tr>
<td style="text-align:left">D</td>
<td style="text-align:left">500</td>
</tr>
<tr>
<td style="text-align:left">CD</td>
<td style="text-align:left">400</td>
</tr>
<tr>
<td style="text-align:left">C</td>
<td style="text-align:left">100</td>
</tr>
<tr>
<td style="text-align:left">XC</td>
<td style="text-align:left">90</td>
</tr>
<tr>
<td style="text-align:left">L</td>
<td style="text-align:left">50</td>
</tr>
<tr>
<td style="text-align:left">XL</td>
<td style="text-align:left">40</td>
</tr>
<tr>
<td style="text-align:left">X</td>
<td style="text-align:left">10</td>
</tr>
<tr>
<td style="text-align:left">IX</td>
<td style="text-align:left">9</td>
</tr>
<tr>
<td style="text-align:left">V</td>
<td style="text-align:left">5</td>
</tr>
<tr>
<td style="text-align:left">IV</td>
<td style="text-align:left">4</td>
</tr>
<tr>
<td style="text-align:left">I</td>
<td style="text-align:left">1</td>
</tr>
</tbody>
</table>
<p>&#x4E8E;&#x662F;&#xFF0C;&#x201C;&#x5C06;&#x6574;&#x6570;&#x8F6C;&#x6362;&#x4E3A;&#x963F;&#x62C9;&#x4F2F;&#x6570;&#x5B57;&#x201D;&#x7684;&#x8FC7;&#x7A0B;&#xFF0C;&#x5C31;&#x662F;&#x6211;&#x4EEC;&#x7528;&#x4E0A;&#x9762;&#x8FD9;&#x5F20;&#x8868;&#x4E2D;&#x53F3;&#x8FB9;&#x7684;&#x6570;&#x5B57;&#x4F5C;&#x4E3A;&#x201C;&#x52A0;&#x6CD5;&#x56E0;&#x5B50;&#x201D;&#x53BB;&#x5206;&#x89E3;&#x4E00;&#x4E2A;&#x6574;&#x6570;&#xFF0C;&#x5E76;&#x4E14;&#x5206;&#x89E3;&#x7684;&#x6574;&#x6570;&#x4E2A;&#x6570;&#x8D8A;&#x5C11;&#x8D8A;&#x597D;&#xFF0C;&#x5373;&#x5C3D;&#x91CF;&#x4F7F;&#x7528;&#x9760;&#x524D;&#x7684;&#x6570;&#x5B57;&#xFF0C;&#x8FD9;&#x53EF;&#x4EE5;&#x8BA4;&#x4E3A;&#x662F;&#x4E00;&#x79CD;&#x8D2A;&#x5FC3;&#x6CD5;&#x5219;&#x3002;</p>
<pre class="language-"><code class="lang-JavaScript">var intToRoman = function(num) {
    var nums = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
    var romans = [&quot;M&quot;, &quot;CM&quot;, &quot;D&quot;, &quot;CD&quot;, &quot;C&quot;, &quot;XC&quot;, &quot;L&quot;, &quot;XL&quot;, &quot;X&quot;, &quot;IX&quot;, &quot;V&quot;, &quot;IV&quot;, &quot;I&quot;]

    var index = 0
    var res = &apos;&apos;
    while (index &lt; 13){
        while(num &gt;nums[index] || num == nums[index]){
            res += romans[index]
            num -= nums[index]
        }
        index += 1
    } 
    return res          
};
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; YoungGary 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-01-03 16:31:06
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="11.html" class="navigation navigation-prev " aria-label="Previous page: 11.盛最多水的容器">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="13.html" class="navigation navigation-next " aria-label="Next page: 13.罗马数字转整数">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"12.整数转罗马数字","level":"1.2.8","depth":2,"next":{"title":"13.罗马数字转整数","level":"1.2.9","depth":2,"path":"leetcode/13.md","ref":"leetcode/13.md","articles":[]},"previous":{"title":"11.盛最多水的容器","level":"1.2.7","depth":2,"path":"leetcode/11.md","ref":"leetcode/11.md","articles":[]},"dir":"ltr"},"config":{"plugins":["theme-comscore","prism","-highlight","copy-code-button","search-pro","-search","-lunr","expandable-chapters","splitter","-sharing","tbfed-pagefooter","anchor-navigation-ex"],"styles":{},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy YoungGary 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prismjs/themes/prism-solarizedlight.css"],"lang":{"shell":"bash"}},"splitter":{},"search-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"theme-comscore":{},"copy-code-button":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"Gary","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Gary的小窝","language":"zh-hans","gitbook":"*","description":"Gary的小窝. 里面包含了个人撰写的技术文章"},"file":{"path":"leetcode/12.md","mtime":"2020-01-03T08:31:06.074Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-09-09T14:10:10.930Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

